#include "widget.h"
#include "ui_widget.h"
#include <QPushButton>
#include <QDir>
#include <QProcess>

int const Widget::EXIT_CODE_REBOOT = -123456789;

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);
    QPushButton *pButton = ui->pushButton;
    pButton->setText(QStringLiteral("重启"));
    connect(pButton, SIGNAL(clicked(bool)), this, SLOT(reboot()));
}

void Widget::reboot()
{
//    qApp->exit(Widget::EXIT_CODE_REBOOT);
    QString program = QApplication::applicationFilePath();
    QStringList arguments = QApplication::arguments();
    QString workingDirectory = QDir::currentPath();
    QProcess::startDetached(program, arguments, workingDirectory);
    QApplication::exit();
}

Widget::~Widget()
{
    delete ui;
}
